//
//  SSItemDetailViewController.swift
//  拾舍清洁
//
//  Created by sky.wei on 2023/2/23.
//

import UIKit

import SwiftyJSON


class SSItemDetailViewController: UIViewController {
    
    @IBOutlet weak var closeBtn: UIImageView!
    var id = ""
    
//    @IBOutlet weak var subImg: UIImageView!
//
//    @IBOutlet weak var imageView: UIImageView!
    
    var scrollView = UIScrollView()
    var imageV = UIImageView()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        title = "详情"
    print("--宽\(ScreenWidth)")
    print("--高\(ScreenHeight)")
        
        network()
        setupUIs()
    }

    func setupUIs() {
        let scrollView = UIScrollView()
        scrollView.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenHeight)
        view.addSubview(scrollView)
//        scrollView.contentSize = CGSize(width: ScreenWidth, height: ScreenHeight)
        self.scrollView = scrollView
        
        let imageV = UIImageView()
        imageV.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: scrollView.frame.height)
        scrollView.addSubview(imageV)
        self.imageV = imageV
        view.sendSubviewToBack(scrollView)
    }
    
    //MARK: -networing
    //list
    func network() {
        let param = [
                    "id": self.id
        ] as [String:AnyObject]
        SSProgressHUD.share.show()
        HttpConnectTools.share.request(urlString: APIUrl.share.getItemDetail_URL, parameters: param) { (result, error) in
            SSProgressHUD.share.dismiss()
            if let _ = result{
                let json = JSON(parseJSON: result!)
                let data = json["data"]["listItemDetail"].arrayValue
                if data.count > 0 {
                    let dic:JSON = data.first ?? ""
                    let url = dic["itemTextUrl"].stringValue
                    self.imageV.setImage(with: url, placeholderImage: UIImage(named: "")) { image, error in
                        let widthImg:CGFloat = 430
                        let heightImg:CGFloat = 932
                        let widthImageV:CGFloat = ScreenWidth
                        let heightImageV:CGFloat = widthImageV * (heightImg/widthImg)
                        self.scrollView.contentSize = CGSize(width: ScreenWidth, height: heightImageV)
                        self.imageV.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: heightImageV)
                    }
                }
            }else{
            }
        }
    }

  
    @IBAction func closeAction(_ sender: Any) {
        dismiss(animated: true)
    }
    
}
//"http://ec2-43-207-36-225.ap-northeast-1.compute.amazonaws.com:8090/img/xq.png"
